package niuke;

import java.util.Scanner;

public class Thelargestnumber {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int currentSize=0;
		int t=0;
		while (scanner.hasNextLine()) {
			int M=scanner.nextInt();
			int mod=scanner.nextInt();
			
			int blockNum=(int)(Math.sqrt(M));
			int numOfEachBlock=M/blockNum;
			if(M%blockNum!=0){
				blockNum++;
			}
			
			int[] a=new int[M];
			int[] max=new int[blockNum];
			
			for (int i = 0; i < M; i++) {
				char type=scanner.next().charAt(0);
				if(type=='Q'){
					int L=scanner.nextInt();
					L=currentSize-L;
					int j;
					
					int LBlockIndex=L/numOfEachBlock+1;
					int LLast=(LBlockIndex)*numOfEachBlock-1;
					if(LLast>currentSize-1){
						LLast=currentSize-1;
					}
					int result=0;
					for (j=(currentSize-1)/numOfEachBlock;j>=LBlockIndex;j--){
						result=Math.max(result, max[j]);
					}
					for (j = L; j <=LLast ; j++) {
						result=Math.max(result, a[j]);
					}
					t=result;
					System.out.println(result);
				}else {
					int N=scanner.nextInt();
					int numToAdd=(N+t)%mod;
					a[currentSize]=numToAdd;

					int lastBlockIndex=currentSize/numOfEachBlock;
					if(numToAdd>max[lastBlockIndex]){
						max[lastBlockIndex]=numToAdd;
					}
					currentSize++;
				}
			}
		}
	}
}
